// 获取当前日期 / 转换时间格式
export function getDate(time) {
	let date = time ? new Date(time) : new Date(),
		year = date.getFullYear(),
		month = date.getMonth() + 1,
		day = date.getDate();
	month >= 1 && month <= 9 ? (month = "0" + month) : "";

	let timer = year + '-' + month + '-' + day;
	return timer;
}

// 获取当前时间 / 转换时间格式 HH:mm
export function getTime(time) {
	let date = time ? new Date(time) : new Date(),
		// year = date.getFullYear(),
		// month = date.getMonth() + 1,
		// day = date.getDate(),
		hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
		minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
		// second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
	// month >= 1 && month <= 9 ? (month = "0" + month) : "";
	// day >= 0 && day <= 9 ? (day = "0" + day) : "";
	// let timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
	let timer = hour + ':' + minute;
	return timer;
}

//cron表达式  转换 HH:mm
export function formatTime(time) {
	if(!time){
		return 
	}
	let timer = time.split(' ')
	let hour = timer[2]
	let minute = timer[1]
	return hour+':'+minute
}

// 时间戳 转为 cron表达式
export function formatCorn(mss) {
	// 0 15 10 * * * ? 每天上午10:15触发
	if(!mss){
		return 
	}
	let hour = mss.split(':')[0]
	let min = mss.split(':')[1]
	return '0' + ' ' + min + ' ' + hour + ' ' + '* * ?'
}
